package com.ruoyi.system.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.FitSleep;
import com.ruoyi.system.service.IFitSleepService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 睡眠记录Controller
 * 
 * @author ruoyi
 * @date 2025-05-14
 */
@Controller
@RequestMapping("/system/sleep")
public class FitSleepController extends BaseController
{
    private String prefix = "system/sleep";

    @Autowired
    private IFitSleepService fitSleepService;

    @RequiresPermissions("system:sleep:view")
    @GetMapping()
    public String sleep()
    {
        return prefix + "/sleep";
    }

    /**
     * 查询睡眠记录列表
     */
    @RequiresPermissions("system:sleep:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(FitSleep fitSleep)
    {
        startPage();
        List<FitSleep> list = fitSleepService.selectFitSleepList(fitSleep);
        return getDataTable(list);
    }

    /**
     * 导出睡眠记录列表
     */
    @RequiresPermissions("system:sleep:export")
    @Log(title = "睡眠记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(FitSleep fitSleep)
    {
        List<FitSleep> list = fitSleepService.selectFitSleepList(fitSleep);
        ExcelUtil<FitSleep> util = new ExcelUtil<FitSleep>(FitSleep.class);
        return util.exportExcel(list, "睡眠记录数据");
    }

    /**
     * 新增睡眠记录
     */
    @RequiresPermissions("system:sleep:add")
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存睡眠记录
     */
    @RequiresPermissions("system:sleep:add")
    @Log(title = "睡眠记录", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(FitSleep fitSleep)
    {
        return toAjax(fitSleepService.insertFitSleep(fitSleep));
    }

    /**
     * 修改睡眠记录
     */
    @RequiresPermissions("system:sleep:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        FitSleep fitSleep = fitSleepService.selectFitSleepById(id);
        mmap.put("fitSleep", fitSleep);
        return prefix + "/edit";
    }

    /**
     * 修改保存睡眠记录
     */
    @RequiresPermissions("system:sleep:edit")
    @Log(title = "睡眠记录", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(FitSleep fitSleep)
    {
        return toAjax(fitSleepService.updateFitSleep(fitSleep));
    }

    /**
     * 删除睡眠记录
     */
    @RequiresPermissions("system:sleep:remove")
    @Log(title = "睡眠记录", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(fitSleepService.deleteFitSleepByIds(ids));
    }
}
